package cn.wolfcode.wolf2w.business.controller;

import cn.wolfcode.wolf2w.business.util.SmsUtil;
import cn.wolfcode.wolf2w.common.core.domain.R;
import cn.wolfcode.wolf2w.common.redis.service.RedisService;
import cn.wolfcode.wolf2w.common.redis.util.RedisKeys;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Random;
import java.util.concurrent.TimeUnit;

@RestController
@RequestMapping("/sms")
public class SmsController {
    @Autowired
    private RedisService redisService;



    @PostMapping("/sendVerifyCode")
    public R<?> sendVerifyCode(String phone){

//        String substring = UUID.randomUUID().toString().replace("-", "").substring(4);
        Random random = new Random();
        Integer randnum = random.nextInt(9000) + 1000;
        String code = randnum.toString();
        System.err.println("验证码 : " + code);
        String key = RedisKeys.VERIFY_CODE.join(phone);
        redisService.setCacheObject(key,code,RedisKeys.VERIFY_CODE.getTime(), TimeUnit.SECONDS);
        //SmsUtil.sendSmsAli(phone,code);
        return R.ok();

    }
}
